package com.ruoyi.yn.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.yn.vo.YnWxUserVo;
import com.ruoyi.yn.service.IYnWxUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 微信小程序授权信息Controller
 *
 * @author Tellsea
 * @date 2023-04-24
 */
@Api(tags = "微信小程序授权信息Controller")
@RestController
@RequestMapping("/yn-app/wxUser")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class YnWxUserController extends BaseController {

    private final IYnWxUserService ynWxUserService;

    @ApiOperation("查询微信小程序授权信息列表")
    @PreAuthorize("@ss.hasPermi('yn-app:wxUser:list')")
    @GetMapping("/list")
    public TableDataInfo<YnWxUserVo> list(YnWxUserVo entity) {
        return ynWxUserService.queryList(entity);
    }

    @ApiOperation("查询微信小程序授权信息所有列表")
    @GetMapping("/listAll")
    public AjaxResult listAll(YnWxUserVo entity) {
        return AjaxResult.success("查询成功", ynWxUserService.queryAll(entity));
    }

    @ApiOperation("导出微信小程序授权信息列表")
    @PreAuthorize("@ss.hasPermi('yn-app:wxUser:export')")
    @Log(title = "微信小程序授权信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YnWxUserVo entity) {
        List<YnWxUserVo> list = ynWxUserService.queryAll(entity);
        ExcelUtil<YnWxUserVo> util = new ExcelUtil<>(YnWxUserVo.class);
        util.exportExcel(response, list, "微信小程序授权信息数据");
    }

    @ApiOperation("获取微信小程序授权信息详细信息")
    @PreAuthorize("@ss.hasPermi('yn-app:wxUser:query')")
    @GetMapping(value = "/getInfo/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success("查询成功", ynWxUserService.queryById(id));
    }

    @ApiOperation("新增微信小程序授权信息")
    @PreAuthorize("@ss.hasPermi('yn-app:wxUser:add')")
    @Log(title = "微信小程序授权信息", businessType = BusinessType.INSERT)
    @PostMapping("add")
    public AjaxResult add(@RequestBody YnWxUserVo entity) {
        return toAjax(ynWxUserService.save(entity));
    }

    @ApiOperation("修改微信小程序授权信息")
    @PreAuthorize("@ss.hasPermi('yn-app:wxUser:edit')")
    @Log(title = "微信小程序授权信息", businessType = BusinessType.UPDATE)
    @PostMapping("edit")
    public AjaxResult edit(@RequestBody YnWxUserVo entity) {
        return toAjax(ynWxUserService.updateById(entity));
    }

    @ApiOperation("删除微信小程序授权信息")
    @PreAuthorize("@ss.hasPermi('yn-app:wxUser:remove')")
    @Log(title = "微信小程序授权信息", businessType = BusinessType.DELETE)
	@GetMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(ynWxUserService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
